package com.zt.ztyh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zt.ztyh.service.ZtyhRecordingService;
import com.zt.ztyh.mapper.ZtyhRecordingMapper;
import com.zt.ztyh.utils.IdWorker;
import com.zt.ztyh.entity.ZtyhRecording;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @author JIASC
 * @description 针对表【ztyh_recording】的数据库操作Service实现
 * @createDate 2024-04-02 20:12:18
 */
@Service
public class ZtyhRecordingServiceImpl extends ServiceImpl<ZtyhRecordingMapper, ZtyhRecording>
        implements ZtyhRecordingService {

    @Autowired
    private ZtyhRecordingMapper ztyhRecordingMapper;

    @Override
    public boolean addRecording(ZtyhRecording ztyhRecording) {
        IdWorker idWorker = new IdWorker();
        ztyhRecording.setId(idWorker.nextId());
        return ztyhRecordingMapper.insert(ztyhRecording) == 1;
    }


    @Override
    public List<ZtyhRecording> getList(Long userId, String startTimec, String endTimec) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date startTime = null;
        Date endTime = null;
        if (Objects.isNull(startTimec) && !Objects.isNull(endTimec)) {
            try {
                startTime = simpleDateFormat.parse("1970-1-1");
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
        }
        if (!Objects.isNull(startTimec) && Objects.isNull(endTimec)) {
            endTime = new Date();
        }
        if (!Objects.isNull(startTimec) && !Objects.isNull(endTimec)) {
            try {
                startTime = simpleDateFormat.parse(startTimec);
                endTime = simpleDateFormat.parse(endTimec);
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
        }
        if (Objects.isNull(startTime) && Objects.isNull(endTime)) {
            try {
                startTime = simpleDateFormat.parse("1970-1-1 00:00:00");
                endTime = new Date();
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
        }
        return ztyhRecordingMapper.getList(userId, startTime, endTime);
    }

    @Override
    public List<ZtyhRecording> selectZtyhRecordings(Long userId, String startTime, String endTime) {
        return this.ztyhRecordingMapper.selectZtyhRecording(userId, startTime, endTime);
    }

    @Override
    public List<ZtyhRecording> getUserListTime(Long userId, int openType) {
        return this.ztyhRecordingMapper.getUserListTime(userId, openType);
    }
}




